﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ledict.ConditionExtract.DAL;
using System.Data;
using Ledict.ConditionExtract.Model;
using System.Windows.Forms;

namespace Ledict.ConditionExtract.BLL
{
    public class SYS_InfoElementsBLL
    {
        SYS_InfoElementsDAL dal = new SYS_InfoElementsDAL();

        /// <summary>
        /// 获取要素中心节点树第一级节点和根据父级获取子节点
        /// </summary>
        /// <param name="pid">父级节点</param>
        /// <returns></returns>
        public DataTable NodeTree_Tree(string pid)
        {
            return dal.NodeTree_Tree(pid.Trim());
        }

        /// <summary>
        /// 获取要素中心节点类型
        /// </summary>
        /// <param name="ccId"></param>
        /// <returns></returns>
        public DataTable GetInfoElementsType()
        {
            return dal.GetInfoElementsType();
        }

        /// 得到一个对象实体
        /// </summary>
        public SYS_InfoElements GetInfoElementsByEICid(string EIC_ID)
        {
            return dal.GetInfoElementsByEICid(EIC_ID);
        }

        /// <summary>
        ///获取一个要素节点的父级的第一个流程性节点
        /// </summary>
        /// <param name="cc_ID"></param>
        /// <returns></returns>
        public DataTable IsParentInfoElements(string EIC_ID)
        {
            return dal.IsParentInfoElements(EIC_ID);
        }

        /// <summary>
        /// 根据要素ID获取要素节点信息和要素xml结构
        /// </summary>
        public DataTable GetInfoElementsAndStructureByEICid(string EIC_ID)
        {
            return dal.GetInfoElementsAndStructureByEICid(EIC_ID);
        }


        /// <summary>
        /// 根据EIC_ID判断该节点下是否有属性xml节点
        /// </summary>
        /// <param name="ccID"></param>
        /// <returns></returns>
        public string IsHaveProperty(string EIC_ID)
        {
            return dal.IsHaveProperty(EIC_ID);
        }

        /// <summary>
        /// 添加属性后更改排序
        /// </summary>
        /// <param name="ccID"></param>
        /// <returns></returns>
        public void AddPropertyUpdateSerialNum(string EIC_ID)
        {
             dal.AddPropertyUpdateSerialNum(EIC_ID);
        }

        /// <summary>
        /// 添加要素节点
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public bool AddSYS_InfoElements(SYS_InfoElements Model, string username)
        {
            return dal.AddSYS_InfoElements(Model, username);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public bool UpdateSYS_InfoElements(SYS_InfoElements Model, string username)
        {
            return dal.UpdateSYS_InfoElements(Model, username);
        }

        /// <summary>
        /// 获取节点下面子节点的排序序号
        /// </summary>
        /// <param name="cc_ID"></param>
        /// <param name="NeedLast">true 最大序号 false 最大序号+1</param>
        /// <returns></returns>
        public decimal GetNodeChildSerialNumber(string cc_ID, bool NeedLast = false)
        {
            return dal.GetNodeChildSerialNumber(cc_ID, NeedLast);
        }

        /// <summary>
        ///  插入要素XML
        /// </summary>
        /// <param name="EIC_ID"></param>
        /// <param name="sieModel"></param>
        /// <returns></returns>
        public bool InsertElementXML(string EIC_ID, SYS_ElementStructure sieModel)
        {
            return dal.InsertElementXML(EIC_ID, sieModel);
        }

        /// <summary>
        /// 父节点下是否存在要素节点
        /// </summary>
        public string Exists(string EIC_Name, string EIC_ParentID)
        {
          return   dal.Exists(EIC_Name, EIC_ParentID);
        }

        /// <summary>
        ///  修改（XML）
        /// </summary>
        /// <param name="CC_ID"></param>
        /// <param name="EI_ID"></param>
        /// <returns></returns>
        public bool UpdateElementXML(string EIC_ID, string ElementXML)
        {
            return dal.UpdateElementXML(EIC_ID, ElementXML);
        }

        /// <summary>
        /// 删除要素节点(当前节点及其节点下级)
        /// </summary>
        /// <param name="EIC_ID"></param>
        /// <param name="username"></param>
        /// <returns></returns>
        public bool DeleteSYS_InfoElements(string EIC_ID, string username)
        {
            return dal.DeleteSYS_InfoElements(EIC_ID, username);
        }

        /// <summary>
        /// 删除要素节点(节点下级)
        /// </summary>
        /// <param name="EIC_ID"></param>
        /// <param name="username"></param>
        /// <returns></returns>
        public bool DeleteSYS_InfoElements1(string EIC_ID, string username)
        {
            return dal.DeleteSYS_InfoElements1(EIC_ID, username);
        }
        /// <summary>
        /// 删除要素节点(当前节点)
        /// </summary>
        /// <param name="EIC_ID"></param>
        /// <param name="username"></param>
        /// <returns></returns>
        public bool DeleteSYS_InfoElementsByEICID(string EIC_ID, string username)
        {
            return dal.DeleteSYS_InfoElementsByEICID(EIC_ID, username);
        }

        /// <summary>
        /// 根据节点名称或者节点ID模糊搜索
        /// </summary>
        /// <param name="FirPid"></param>
        /// <param name="name"></param>
        /// <param name="TreeNumber"></param>
        /// <returns></returns>
        public DataTable GetInfoElementSearch(string FirPid, string name)
        {
            return dal.GetInfoElementSearch(FirPid, name);
        }

        /// <summary>
        /// 根据EIC_ID获取该节点下是否配置了来源规则
        /// </summary>
        /// <param name="ccID"></param>
        /// <returns></returns>
        public bool GetExpressSourceByEIC_ID(string EIC_ID)
        {
            return dal.GetExpressSourceByEIC_ID(EIC_ID);
        }

        /// <summary>
        /// 根据节点获取节点下面的节点类型
        /// </summary>
        /// <param name="CC_ID"></param>
        /// <returns></returns>
        public List<SYS_InfoElementsType> GetInfoElementsTypeByEICId(string CC_ID)
        {
            return dal.GetInfoElementsTypeByEICId(CC_ID);
        }

        /// <summary>
        ///判断目标节点是否是原节点的子集 
        /// </summary>
        /// <param name="cc_ID"></param>
        /// <returns></returns>
        public bool IsParentRealation(string source_ID, string target_ID)
        {
            return dal.IsParentRealation(source_ID, target_ID);
        }


        /// <summary>
        /// 根据CCID获取下级节点名称
        /// </summary>
        /// <param name="ccID"></param>
        /// <returns></returns>
        public List<string> GetTongJiNodes(string ccID)
        {
            return dal.GetTongJiNodes(ccID);
        }

        /// <summary>
        ///获取一个节点的父级的第一个案由节点
        /// </summary>
        /// <param name="cc_ID"></param>
        /// <returns></returns>
        public SYS_InfoElements IsParentRealation1(string ccID)
        {
            return dal.IsParentRealation1(ccID);
        }

        /// <summary>
        /// 更改节点排序
        /// </summary>
        /// <param name="sourceItemId"></param>
        /// <param name="targetItemId"></param>
        /// <returns></returns>
        public bool UpdateItemSort(SYS_InfoElements sourceItem, SYS_InfoElements targetItem, string moveState)
        {
            return dal.UpdateItemSort(sourceItem, targetItem, moveState);
        }

        /// <summary>
        /// 获取节点的下级所有子节点
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public DataTable GetInfoElementsNodes(string ccID)
        {
            return dal.GetInfoElementsNodes(ccID);
        }

        // <summary>
        /// 获得批量数据列表
        /// </summary>
        /// <param name="parentId">父节点</param>
        /// <param name="ccNodeTypes">节点类型列表</param>
        /// <param name="isHasParentId">查询结果是否包括父节点（默认包括）</param>
        /// <returns></returns>
        public DataTable GetInfoElementsBatchSource(string parentId, IList<string> ccNodeTypes, bool isHasParentId = true)
        {
            return dal.GetInfoElementsBatchSource(parentId, ccNodeTypes);
        }
        }
}
